home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1997 August / Walnut Creek CDROM.7z / LISTINGS / V_12_11 / ALLISON / CLASS.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-04  |  1.0 KB  |  53 lines

  1. LISTING 24 - Illustrates the behavior of class-specific new and
  2. delete (see Listing 23)
  3.  
  4. // class.cpp
  5. #include <iostream.h>
  6. #include "t.h"
  7.  
  8. main()
  9. {
  10.     cout << "allocating a T:" << endl;
  11.     T *t1 = new T;
  12.     cout << endl;
  13.  
  14.     cout << "allocating an array of 3 T's:" << endl;
  15.     T *t2 = new T[3];
  16.     cout << endl;
  17.  
  18.     cout << "allocating a T with initialization:" << endl;
  19.     T *t3 = new T(2);
  20.     cout << endl;
  21.  
  22.     cout << "allocating a U:" << endl;
  23.     U *u1 = new U;
  24.     cout << endl;
  25.  
  26.     cout << "allocating an array of 2 U's:" << endl;
  27.     U *u2 = new U[2];
  28.     cout << endl;
  29.  
  30.     cout << "deleting a T:" << endl;
  31.     delete t1;
  32.     cout << endl;
  33.  
  34.     cout << "deleting the array of 3 T's:" << endl;
  35.     delete [] t2;
  36.     cout << endl;
  37.  
  38.     cout << "deleting another T:" << endl;
  39.     delete t3;
  40.     cout << endl;
  41.  
  42.     cout << "deleting the U:" << endl;
  43.     delete u1;
  44.     cout << endl;
  45.  
  46.     cout << "deleting the array of 2 U's:" << endl;
  47.     delete [] u2;
  48.     cout << endl;
  49.  
  50.     return 0;
  51. }
  52.  
  53.